﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;
using System.Data;

public partial class ChiTietTraLoi : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["IdLienHe"] != null)
        {
            H_SachId.Value = Request.Params["IdLienHe"].ToString();
            View_IdLienHe(new Guid(H_SachId.Value.ToString()));
            View_TraLoi(new Guid(H_SachId.Value.ToString()));
        }
        HienThiLoaiTin();
    }

    protected void View_IdLienHe(Guid IdLienHe)
    {
        LienHe ent_LienHe = DataRepository.LienHeProvider.GetById(new Guid (IdLienHe.ToString()));
        try
        {
            if (ent_LienHe != null)
            {
                int TotalRows = 0;
                int ChiaSe = 0;
                lbHoTen.Text = ent_LienHe.HoTen;
                lbThuDienTu.Text = ent_LienHe.ThuDienTu;
                lbTieuDe.Text = ent_LienHe.TieuDe;
                lbNgayCapNhat.Text = Common.StandardStringjquery(ent_LienHe.NgayCapNhat.ToString("dd/MM/yyyy"));
                lbNoiDung.Text = ent_LienHe.NoiDung;
                Session["Title"] = ent_LienHe.TieuDe;

            }
        }
        catch (Exception ex) { }
    }
    protected void View_TraLoi(Guid IdLienHe)
    {
        TList<TraLoi> Tlist_TraLoi = DataRepository.TraLoiProvider.GetByIdLienHe(new Guid(IdLienHe.ToString()));
        dlTraLoi.DataSource = Tlist_TraLoi;
        dlTraLoi.DataBind();
    }

    protected void cmdFacebook_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://www.facebook.com/sharer.php?u=" + Common.sPathUpLienKet + "/ChiTietTraLoi.aspx?TraLoiId=" + Convert.ToInt32(H_SachId.Value) + "&&TieuDe" + GetTieuDe(H_TieuDe.Value));
        }
        catch (Exception ex)
        { }
    }
    protected void cmdTwiter_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://twitter.com/home?status=" + Common.sPathUpLienKet + "/ChiTietTraLoi.aspx?TraLoiId=" + Convert.ToInt32(H_SachId.Value) + "&&TieuDe" + GetTieuDe(H_TieuDe.Value));
        }
        catch (Exception ex)
        { }
    }
    protected void cmdYahoo_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("ymsgr:im?+&msg=Xem bài này hay lắm nè: " + Common.sPathUpLienKet + "/ChiTietTraLoi.aspx?TraLoiId=" + Convert.ToInt32(H_SachId.Value) + "&&TieuDe" + GetTieuDe(H_TieuDe.Value));
        }
        catch (Exception ex)
        { }
    }
    protected void cmdEmail_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("https://mail.google.com/mail/?view=cm&fs=1&to&su=" + Convert.ToString(Session["Title"]) + "&body=" + Common.sPathUpLienKet + "/ChiTietTraLoi.aspx?TraLoiId=" + Convert.ToInt32(H_SachId.Value) + "&&TieuDe" + GetTieuDe(H_TieuDe.Value) + "%23.TwF6mDNohJo.gmail&ui=2&tf=1&shva=1");
        }
        catch (Exception ex)
        { }
    }
    protected void cmdZing_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Response.Redirect("http://link.apps.zing.vn/share?u=" + Common.sPathUpLienKet + "/ChiTietTraLoi.aspx?TraLoiId=" + Convert.ToInt32(H_SachId.Value) + "&&TieuDe" + GetTieuDe(Convert.ToString(Session["Title"])) + "&images=&media=&width=0&height=0");
        }
        catch (Exception ex)
        { }
    }
    protected void cmdSend_Click(object sender, ImageClickEventArgs e)
    {
        bool updateStatus = false;
        try
        {
        }
        catch (Exception ex)
        {
            Common.WriteLog("ChiTietTraLoi.aspx.cs", "cmdSend_Click", ex.ToString());
            WebMessage.Show("Cập nhật Comment thất bại!");
        }
    }

    /// <summary>
    /// Hiển thị Loại tin
    /// </summary>
    private void HienThiLoaiTin()
    {
        int TotalRows = 0;
        TList<LienHe> TList_LienHe = DataRepository.LienHeProvider.GetPaged("", "NgayCapNhat DESC", 0, 10, out TotalRows);
        dlLoaiTinTuc.DataSource = TList_LienHe;
        dlLoaiTinTuc.DataBind();
    }

    public string GetLienKet()
    {
        return Common.sPathUpLienKet;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    public string GetNgay(object ngayviet)
    {
        DateTime s = Convert.ToDateTime(ngayviet);
        string v = s.ToString("dd/MM/yyyy");
        return Common.StandardStringjquery(v);
    }
}